package practice03;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author Administrator
 * @version V1.0
 * @ProjectName:IntelliJ IDEA
 * @PackageName: practice03
 * @ClassName: Login
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @date 2019/12/30 18:43
 * @Copyright 大牛版板所有
 */
public class Login {
    public static void main(String[] args) {
        Socket loginClient = null;
        ObjectOutputStream oos = null;
        Scanner input = new Scanner(System.in);
        BufferedReader response = null;
        User user = new User();
        try {
            loginClient = new Socket("192.168.1.141",9000);
            oos = new ObjectOutputStream(loginClient.getOutputStream());
            response = new BufferedReader(new InputStreamReader(loginClient.getInputStream()));

            System.out.print("请输入登录账户：");
            user.setUsername(input.next());
            System.out.print("请输入密码：");
            user.setPassword(input.next());
            oos.writeObject(user);

            String isTrue = response.readLine();
            if ("正确".equals(isTrue)){
                System.out.println("登录成功！");
            }
            else {
                System.out.println("密码或账户错误,请重新输入！");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (loginClient != null){
                try {
                    loginClient.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
